package org.ch02.sk.demo07;

import java.beans.*;

/**
 * @author XCH
 * @date 2025 - 03 - 24
 */
public class MainTest {
    public static void main(String[] args) throws Exception {
        // 获取Person类的所有属性和方法信息
        //
        //Introspector.getBeanInfo(Person.class, Object.class)
        //BeanInfo beanInfo = Introspector.getBeanInfo(Person.class, Object.class);
        //PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
        //System.out.println(propertyDescriptors.length);
//        for (PropertyDescriptor propertyDescriptor : propertyDescriptors){
//            System.out.println(propertyDescriptor.getName());
//        }
//        try {
//            // 尝试获取不存在的属性 "address" 的描述符
//            PropertyDescriptor pd = new PropertyDescriptor("address", Person.class);
//        } catch (IntrospectionException e) {
//            System.err.println("错误: " + e.getMessage());
//            // 输出: 错误: No getter method for property address in class Person
//        }
        try {
            // 尝试获取私有方法的描述符（会失败）
            MethodDescriptor md = new MethodDescriptor(
                    Person.class.getDeclaredMethod("privateMethod")
            );
        } catch (NoSuchMethodException e) {
            System.err.println("错误: " + e.getMessage());
            // 输出: 错误: Method privateMethod is not public
        }
    }
}
